package ua.org.enginer.controls
{
	import flash.events.Event;
	import mx.controls.ComboBox;
	
	public class TimeSelector extends ComboBox {
		
		public static const HOUR_IN_MILLISECONDS : Number = 60 * 60 * 1000;
		
		public function TimeSelector() {
			super();
			width = 75
			selectedIndex = -1
			//addEventListener("change", onChange)
			//todo: timeInput.editable = true
			var dp:Array = new Array(48)
			var timeStr:String
			
			for (var i:int; i<48; i++) {
				timeStr = String(Math.floor(i/2)+":")
				timeStr += i%2 ? "30" : "00"
				dp[i] = timeStr
			}
			
			dataProvider = dp
		}
		
	
		public function set value(value:Object):void {
			//_selectedTime = value;
			if (!value.time) {
				selectedIndex = -1
				text = ''
				return;
			}
			
			text = value.hoursUTC+":"
			text += value.minutes ? value.minutes : "00"
			selectedItem = text
		}
		
		[Bindable(event="change")]
		override public function get value():Object {
			if (selectedIndex<0) return null;
			var time:Number = selectedIndex*HOUR_IN_MILLISECONDS/2
			return new Date(time);
		}
	}
}